package com.gewu.pm.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.TestBean;

/**
 * 账期单列表适配器
 */
public class PaymentTermAdapter extends AppAdapter<TestBean> {

    public PaymentTermAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ItemViewHolder();
    }

    private final class ItemViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView mDocumentNoView;
        private final TextView mTerminalNameView;
        private final TextView mTerminalCodeView;
        private final TextView mAccountPeriodView;
        private final TextView mBufferPeriodView;
        private final TextView mPeriodTimeView;
        private final TextView mDueDateView;
        private final TextView mPeriodAmountView;
        private final TextView mSettledAmountView;
        private final TextView mVehicleCodeView;
        private final TextView mDeliveryProviderView;
        private final TextView mSalespersonView;

        private ItemViewHolder() {
            super(R.layout.payment_term_item);
            mDocumentNoView = findViewById(R.id.tv_document_no);
            mTerminalNameView = findViewById(R.id.tv_terminal_name);
            mTerminalCodeView = findViewById(R.id.tv_terminal_code);
            mAccountPeriodView = findViewById(R.id.tv_account_period);
            mBufferPeriodView = findViewById(R.id.tv_buffer_period);
            mPeriodTimeView = findViewById(R.id.tv_period_time);
            mDueDateView = findViewById(R.id.tv_due_date);
            mPeriodAmountView = findViewById(R.id.tv_period_amount);
            mSettledAmountView = findViewById(R.id.tv_settled_amount);
            mVehicleCodeView = findViewById(R.id.tv_vehicle_code);
            mDeliveryProviderView = findViewById(R.id.tv_delivery_provider);
            mSalespersonView = findViewById(R.id.tv_salesperson);
        }

        @Override
        public void onBindView(int position) {
            TestBean item = getItem(position);
            // 使用 TestBean 的 name 字段作为显示内容
            mDocumentNoView.setText(item.getName());
            mTerminalNameView.setText(item.getName());
            mTerminalCodeView.setText(item.getId());
            mAccountPeriodView.setText("10天");
            mBufferPeriodView.setText("3天");
            mPeriodTimeView.setText("2025-08-01~2025-08-10");
            mDueDateView.setText("2025-08-13");
            mPeriodAmountView.setText("¥888.80");
            mSettledAmountView.setText("¥888.80");
            mVehicleCodeView.setText("A1111111");
            mDeliveryProviderView.setText("杭州小配送1号车");
            mSalespersonView.setText("张三");
        }
    }
}

